package com.chenfan.ccp.common.exception;

import com.chenfan.ccp.common.result.IResultCode;
import lombok.Data;

/**
 * 类名称：BaseException  
 * 类描述：基础异常类
 * @author leo
 * @date: 2021/1/9 5:11 下午
 */
@Data
public class BaseException extends RuntimeException {
    private static final long serialVersionUID = 7773039158178752257L;


    /**
     * 默认失败码 用户可自行定义默认错误码
     */
    public static int FAIL = -1;

    /**
     * 错误码
     */
    private int code;

    /**
     * 错误消息
     */
    private String msg;

    /**
     * 错误异常源
     */
    private Exception ex;
    
    public BaseException() {
    }
    public BaseException(int code) {
        this(code, null, null);
    }

    public BaseException(String msg) {
        this(FAIL, msg, null);
    }

    public BaseException(int code, String msg) {
        this(code, msg, null);
    }

    public BaseException(int code, String msg, Exception ex) {
        super(msg);
        this.code = code;
        this.msg = msg;
        this.ex = ex;
    }

    public BaseException(IResultCode e) {
        this(e.getCode(), e.getMessage(), null);
    }
    
    public BaseException(Exception ex) {
        this(FAIL, ex.getMessage(), ex);
    }

    public BaseException(IResultCode e,Exception ex) {
        this(e.getCode(), e.getMessage(), ex);
    }

}